'use strict'

function Records(){
	this.values = {};
}

Records.prototype.add = function(row,reader){
	var entity = reader(row),
		existed;

	if( entity!==undefined && entity.key!=undefined ){
		existed = this.values[entity.key];

		if( existed === undefined ){
			entity.depts = {};
			entity.depts[entity.dept] = true;
			this.values[entity.key] = entity;
		} else {
			existed.depts[entity.dept] = true;
		}

	}
}

Records.prototype.filter = function(){
	var key,count = 0,
		singleCount = 0,
		entity;

	for( key in this.values ){
		entity =  this.values[key].depts;
		if( Object.keys(entity).length<2){
			delete this.values[key];
			singleCount ++;
		}
		count ++;
	}
	console.log( ' ==================================');
	console.log('==records filter  before: '+ count +'  singles be filterd: '+ singleCount);
}

Records.prototype.show = function(){
	var key;
	console.log('==================================');
	console.log('====records: ');
	for( key in this.values ){
		console.log( key + ' > '+ this.values[key].time + ' '+ Object.keys(this.values[key].depts) );
	}
}

module.exports = Records;

